﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RapidWebDev.UI.DynamicPages;
using RapidWebDev.UI.Controls;
using TestCenter.Platform.DataModel;
using TestCenter.Platform.Apis;
using RapidWebDev.Platform;
using RapidWebDev.Common;

namespace TestCenter.Platform.Web.DynamicPages
{
    public class BuildDetail : DetailPanelPage
    {
        protected static readonly ITestCenterApi testcenterApi = SpringContext.Current.GetObject<ITestCenterApi>();
        protected static readonly IAuthenticationContext authenticationContext = SpringContext.Current.GetObject<IAuthenticationContext>();

        #region Web Controls

        [Binding("TabContainer/TabPanelBody")]
        protected TextBox TextBoxTitle;

        [Binding("TabContainer/TabPanelBody")]
        protected TextBox TextBoxSummary;

        [Binding("TabContainer/TabPanelBody")]
        protected ComboBox ComboBoxTestplan;
              
        #endregion

        public override string Create()
        {
            Build build = new Build() { Name = TextBoxTitle.Text,Summary = TextBoxSummary.Text,TestPlanId = new Guid( ComboBoxTestplan.SelectedValue),
                CreatedBy = authenticationContext.User.UserId,CreatedOn = DateTime.Now};
            return testcenterApi.SaveBuild(build, ComboBoxTestplan.SelectedValue);
        }

        public override void LoadReadOnlyEntity(string entityId)
        {
            base.LoadReadOnlyEntity(entityId);
        }

        public override void LoadWritableEntity(string entityId)
        {
            base.LoadWritableEntity(entityId);
        }

        public override void Update(string entityId)
        {
            base.Update(entityId);
        }
    }
}
